feat: Make TelegramClient::start() wait for TDLib initialisation#21
Open
feat: Make TelegramClient::start() wait for TDLib initialisation#21
Conversation
Remove the hardcoded 2-second sleep in exec_users_list() by implementing proper synchronisation between the main thread and TDLib's update thread. Changes: - Add promise/future-based initialisation synchronisation to Impl - Signal completion when auth state transitions to any ready state (WAIT_PHONE, WAIT_CODE, WAIT_PASSWORD, or READY) - TelegramClient::start() now blocks until TDLib is ready - Remove unnecessary sleep and unused includes from users.cpp - Add comprehensive tests with mocks for the init synchronisation The client now starts as fast as TDLib allows (typically < 1 second) instead of always waiting 2 seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
exec_users_list()by implementing proper synchronisation between the main thread and TDLib's update threadTelegramClient::start()now blocks until TDLib signals it's ready (via authorization state change)Changes
src/tg/client.cppinit_promise_,init_future_, andinit_completed_members toImplcomplete_initialization()helper that safely signals the promisewait_initialized()method that blocks until TDLib is ready (with 30s timeout)process_authorization_state()to callcomplete_initialization()on meaningful state transitions (WAIT_PHONE,WAIT_CODE,WAIT_PASSWORD, orREADY)TelegramClient::start()to callwait_initialized()src/ctl/users.cppstd::this_thread::sleep_for()workaround<chrono>and<thread>includestests/tg/client_init_test.cpp(new)MockInitSynchronizerclass that mirrors the exact synchronisation logicTest plan
tg-fuse users --listexecutes immediately without 2-second delay